package controller

import (
	"fmt"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
	"gowork/supplierInteractionPlatform/model"
	"strconv"
)

type RespondentController struct {
	Ctx  iris.Context
	T *model.Respondent
}

func (r *RespondentController) PostQueryrespondentoffer() mvc.Result {
	r.T = &model.Respondent{}
	rId, _ := strconv.Atoi(r.Ctx.FormValue("RespondentId"))
	res, err := r.T.QueryRespondentOffer(int64(rId))
	if err != nil{
		return mvc.Response{
			Object : map[string]interface{}{"message": err.Error(), "data": nil, "code":500,},
		}
	}
	return mvc.Response{
		Object : map[string]interface{}{"message": "成功", "data": res, "code":200,},
	}
}

func (r *RespondentController) PostQueryrespondentofferasync() mvc.Result {
	r.T = &model.Respondent{}
	rId, _ := strconv.Atoi(r.Ctx.FormValue("RespondentId"))
	res, err := r.T.QueryRespondentOfferAsync(int64(rId))
	if err != nil{
		return mvc.Response{
			Object : map[string]interface{}{"message": err.Error(), "data": nil, "code":500,},
		}
	}
	return mvc.Response{
		Object : map[string]interface{}{"message": "成功", "data": res, "code":200,},
	}
}

func (r *RespondentController) PostInsertrespondentoffer() mvc.Result {
	var mr model.Respondent
	r.Ctx.ReadJSON(&mr)
	fmt.Println(mr)
	_, err := r.T.SaveRespondentOffer(&mr)
	if err != nil{
		return mvc.Response{
			Object : map[string]interface{}{"message": err.Error(), "data": nil, "code":500,},
		}
	}
	return mvc.Response{
		Object : map[string]interface{}{"message": "成功", "data": nil, "code":200,},
	}
}

func (r *RespondentController) PostInsertrespondentofferasync() mvc.Result {
	var mr model.Respondent
	r.Ctx.ReadJSON(&mr)
	fmt.Println(mr)
	_, err := r.T.SaveRespondentOfferAsync(&mr)
	if err != nil{
		return mvc.Response{
			Object : map[string]interface{}{"message": err.Error(), "data": nil, "code":500,},
		}
	}
	return mvc.Response{
		Object : map[string]interface{}{"message": "成功", "data": nil, "code":200,},
	}
}